using SS;
using System;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Windows.Forms;
namespace TVSGPP.func
{
	public class frmInteractionProduct : Form
	{
		private IContainer components = null;
		private Label label1;
		private Label label2;
		private Label label3;
		private DataGridView dgvGroup;
		private DataGridView dgvProduct;
		private TextBox txtIntraction;
		private Button btnEdit;
		private Button btnSave;
		private Button btnClose;
		private Label label4;
		private DataGridViewTextBoxColumn GpID;
		private DataGridViewTextBoxColumn GpName;
		private DataGridViewTextBoxColumn PID;
		private DataGridViewTextBoxColumn P_Name;
		private DataGridViewTextBoxColumn interaction;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn1;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn2;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn3;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn4;
		private DataGridViewTextBoxColumn dataGridViewTextBoxColumn5;
		private int currPid = 0;
		private int currIndex = -1;
		protected override void Dispose(bool disposing)
		{
			if (disposing && this.components != null)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}
		private void InitializeComponent()
		{
			DataGridViewCellStyle dataGridViewCellStyle = new DataGridViewCellStyle();
			this.label1 = new Label();
			this.label2 = new Label();
			this.label3 = new Label();
			this.dgvGroup = new DataGridView();
			this.dgvProduct = new DataGridView();
			this.txtIntraction = new TextBox();
			this.btnEdit = new Button();
			this.btnSave = new Button();
			this.btnClose = new Button();
			this.label4 = new Label();
			this.dataGridViewTextBoxColumn1 = new DataGridViewTextBoxColumn();
			this.dataGridViewTextBoxColumn2 = new DataGridViewTextBoxColumn();
			this.dataGridViewTextBoxColumn3 = new DataGridViewTextBoxColumn();
			this.dataGridViewTextBoxColumn4 = new DataGridViewTextBoxColumn();
			this.dataGridViewTextBoxColumn5 = new DataGridViewTextBoxColumn();
			this.PID = new DataGridViewTextBoxColumn();
			this.P_Name = new DataGridViewTextBoxColumn();
			this.interaction = new DataGridViewTextBoxColumn();
			this.GpID = new DataGridViewTextBoxColumn();
			this.GpName = new DataGridViewTextBoxColumn();
			((ISupportInitialize)this.dgvGroup).BeginInit();
			((ISupportInitialize)this.dgvProduct).BeginInit();
			base.SuspendLayout();
			this.label1.BackColor = SystemColors.ButtonHighlight;
			this.label1.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label1.Location = new Point(6, 9);
			this.label1.Name = "label1";
			this.label1.Size = new Size(298, 23);
			this.label1.TabIndex = 0;
			this.label1.Text = "Nhóm thuốc";
			this.label1.TextAlign = ContentAlignment.MiddleCenter;
			this.label2.BackColor = SystemColors.ButtonHighlight;
			this.label2.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label2.Location = new Point(310, 9);
			this.label2.Name = "label2";
			this.label2.Size = new Size(311, 23);
			this.label2.TabIndex = 1;
			this.label2.Text = "Thuốc";
			this.label2.TextAlign = ContentAlignment.MiddleCenter;
			this.label3.Anchor = (AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right);
			this.label3.BackColor = SystemColors.ButtonHighlight;
			this.label3.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label3.Location = new Point(626, 9);
			this.label3.Name = "label3";
			this.label3.Size = new Size(268, 23);
			this.label3.TabIndex = 2;
			this.label3.Text = "Tính tương tác";
			this.label3.TextAlign = ContentAlignment.MiddleCenter;
			this.dgvGroup.AllowUserToAddRows = false;
			this.dgvGroup.AllowUserToDeleteRows = false;
			this.dgvGroup.AllowUserToResizeColumns = false;
			this.dgvGroup.AllowUserToResizeRows = false;
			dataGridViewCellStyle.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.dgvGroup.AlternatingRowsDefaultCellStyle = dataGridViewCellStyle;
			this.dgvGroup.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left);
			this.dgvGroup.BackgroundColor = Color.White;
			this.dgvGroup.BorderStyle = BorderStyle.Fixed3D;
			this.dgvGroup.ColumnHeadersHeight = 26;
			this.dgvGroup.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvGroup.ColumnHeadersVisible = false;
			this.dgvGroup.Columns.AddRange(new DataGridViewColumn[]
			{
				this.GpID,
				this.GpName
			});
			this.dgvGroup.Cursor = Cursors.Hand;
			this.dgvGroup.EnableHeadersVisualStyles = false;
			this.dgvGroup.Location = new Point(6, 33);
			this.dgvGroup.MultiSelect = false;
			this.dgvGroup.Name = "dgvGroup";
			this.dgvGroup.RowHeadersVisible = false;
			this.dgvGroup.RowTemplate.DefaultCellStyle.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.dgvGroup.Size = new Size(298, 558);
			this.dgvGroup.TabIndex = 0;
			this.dgvGroup.CellEnter += new DataGridViewCellEventHandler(this.dgvGroup_CellEnter);
			this.dgvProduct.AllowUserToAddRows = false;
			this.dgvProduct.AllowUserToDeleteRows = false;
			this.dgvProduct.AllowUserToResizeColumns = false;
			this.dgvProduct.AllowUserToResizeRows = false;
			this.dgvProduct.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left);
			this.dgvProduct.BackgroundColor = Color.White;
			this.dgvProduct.BorderStyle = BorderStyle.Fixed3D;
			this.dgvProduct.ColumnHeadersHeight = 26;
			this.dgvProduct.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.DisableResizing;
			this.dgvProduct.ColumnHeadersVisible = false;
			this.dgvProduct.Columns.AddRange(new DataGridViewColumn[]
			{
				this.PID,
				this.P_Name,
				this.interaction
			});
			this.dgvProduct.Cursor = Cursors.Hand;
			this.dgvProduct.EnableHeadersVisualStyles = false;
			this.dgvProduct.Location = new Point(310, 33);
			this.dgvProduct.MultiSelect = false;
			this.dgvProduct.Name = "dgvProduct";
			this.dgvProduct.RowHeadersVisible = false;
			this.dgvProduct.Size = new Size(311, 558);
			this.dgvProduct.TabIndex = 1;
			this.dgvProduct.CellEnter += new DataGridViewCellEventHandler(this.dgvProduct_CellEnter);
			this.txtIntraction.Anchor = (AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.txtIntraction.BackColor = Color.White;
			this.txtIntraction.Location = new Point(626, 33);
			this.txtIntraction.Multiline = true;
			this.txtIntraction.Name = "txtIntraction";
			this.txtIntraction.ReadOnly = true;
			this.txtIntraction.Size = new Size(268, 516);
			this.txtIntraction.TabIndex = 2;
			this.btnEdit.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnEdit.FlatAppearance.BorderColor = Color.Fuchsia;
			this.btnEdit.FlatStyle = FlatStyle.Flat;
			this.btnEdit.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnEdit.Location = new Point(631, 560);
			this.btnEdit.Name = "btnEdit";
			this.btnEdit.Size = new Size(80, 26);
			this.btnEdit.TabIndex = 3;
			this.btnEdit.Text = "Cập nhật";
			this.btnEdit.UseVisualStyleBackColor = true;
			this.btnEdit.Click += new EventHandler(this.btnEdit_Click);
			this.btnSave.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnSave.Enabled = false;
			this.btnSave.FlatAppearance.BorderColor = Color.Fuchsia;
			this.btnSave.FlatStyle = FlatStyle.Flat;
			this.btnSave.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnSave.Location = new Point(712, 560);
			this.btnSave.Name = "btnSave";
			this.btnSave.Size = new Size(86, 26);
			this.btnSave.TabIndex = 4;
			this.btnSave.Text = "Ghi nhận";
			this.btnSave.UseVisualStyleBackColor = true;
			this.btnSave.Click += new EventHandler(this.btnSave_Click);
			this.btnClose.Anchor = (AnchorStyles.Bottom | AnchorStyles.Right);
			this.btnClose.FlatAppearance.BorderColor = Color.Fuchsia;
			this.btnClose.FlatStyle = FlatStyle.Flat;
			this.btnClose.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.btnClose.Location = new Point(799, 560);
			this.btnClose.Name = "btnClose";
			this.btnClose.Size = new Size(90, 26);
			this.btnClose.TabIndex = 5;
			this.btnClose.Text = "Thoát [ ESC ]";
			this.btnClose.UseVisualStyleBackColor = true;
			this.btnClose.Click += new EventHandler(this.btnClose_Click);
			this.label4.Anchor = (AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right);
			this.label4.BackColor = Color.White;
			this.label4.Font = new Font("Arial", 9f, FontStyle.Bold, GraphicsUnit.Point, 163);
			this.label4.Location = new Point(626, 555);
			this.label4.Name = "label4";
			this.label4.Size = new Size(268, 36);
			this.label4.TabIndex = 9;
			this.label4.TextAlign = ContentAlignment.MiddleCenter;
			this.dataGridViewTextBoxColumn1.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.dataGridViewTextBoxColumn1.DataPropertyName = "GpID";
			this.dataGridViewTextBoxColumn1.HeaderText = "Mã nhóm";
			this.dataGridViewTextBoxColumn1.Name = "dataGridViewTextBoxColumn1";
			this.dataGridViewTextBoxColumn1.Visible = false;
			this.dataGridViewTextBoxColumn2.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.dataGridViewTextBoxColumn2.DataPropertyName = "GpName";
			this.dataGridViewTextBoxColumn2.HeaderText = "Tên nhóm";
			this.dataGridViewTextBoxColumn2.Name = "dataGridViewTextBoxColumn2";
			this.dataGridViewTextBoxColumn3.DataPropertyName = "PID";
			this.dataGridViewTextBoxColumn3.HeaderText = "Mã sản phẩm";
			this.dataGridViewTextBoxColumn3.Name = "dataGridViewTextBoxColumn3";
			this.dataGridViewTextBoxColumn3.Visible = false;
			this.dataGridViewTextBoxColumn4.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.dataGridViewTextBoxColumn4.DataPropertyName = "P_Name";
			this.dataGridViewTextBoxColumn4.HeaderText = "Tên sản phẩm";
			this.dataGridViewTextBoxColumn4.Name = "dataGridViewTextBoxColumn4";
			this.dataGridViewTextBoxColumn5.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.dataGridViewTextBoxColumn5.DataPropertyName = "interaction";
			this.dataGridViewTextBoxColumn5.HeaderText = "Tương tác";
			this.dataGridViewTextBoxColumn5.Name = "dataGridViewTextBoxColumn5";
			this.dataGridViewTextBoxColumn5.Visible = false;
			this.PID.DataPropertyName = "PID";
			this.PID.HeaderText = "Mã sản phẩm";
			this.PID.Name = "PID";
			this.PID.Visible = false;
			this.P_Name.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.P_Name.DataPropertyName = "P_Name";
			this.P_Name.HeaderText = "Tên sản phẩm";
			this.P_Name.Name = "P_Name";
			this.interaction.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.interaction.DataPropertyName = "interaction";
			this.interaction.HeaderText = "Tương tác";
			this.interaction.Name = "interaction";
			this.interaction.Visible = false;
			this.GpID.AutoSizeMode = DataGridViewAutoSizeColumnMode.None;
			this.GpID.DataPropertyName = "GpID";
			this.GpID.HeaderText = "Mã nhóm";
			this.GpID.Name = "GpID";
			this.GpID.Visible = false;
			this.GpName.AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
			this.GpName.DataPropertyName = "GpName";
			this.GpName.HeaderText = "Tên nhóm";
			this.GpName.Name = "GpName";
			base.AutoScaleDimensions = new SizeF(7f, 15f);
			//base.AutoScaleMode = AutoScaleMode.Font;
			base.ClientSize = new Size(900, 600);
			base.Controls.Add(this.btnClose);
			base.Controls.Add(this.btnSave);
			base.Controls.Add(this.btnEdit);
			base.Controls.Add(this.txtIntraction);
			base.Controls.Add(this.dgvProduct);
			base.Controls.Add(this.dgvGroup);
			base.Controls.Add(this.label3);
			base.Controls.Add(this.label2);
			base.Controls.Add(this.label1);
			base.Controls.Add(this.label4);
			this.Font = new Font("Arial", 9f, FontStyle.Regular, GraphicsUnit.Point, 163);
			//base.Icon = (System.Drawing.Icon)componentResourceManager.GetObject("$this.Icon");
			base.KeyPreview = true;
			base.Name = "frmInteractionProduct";
			base.StartPosition = FormStartPosition.CenterScreen;
			this.Text = "KHAI BÁO TÍNH TƯƠNG TÁC CỦA THUỐC";
			base.Load += new EventHandler(this.frmInteractionProduct_Load);
			base.KeyDown += new KeyEventHandler(this.frmInteractionProduct_KeyDown);
			((ISupportInitialize)this.dgvGroup).EndInit();
			((ISupportInitialize)this.dgvProduct).EndInit();
			base.ResumeLayout(false);
			base.PerformLayout();
		}
		public frmInteractionProduct()
		{
			this.InitializeComponent();
		}
		private void getListGroupProduct()
		{
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("SELECT GpID,GpName FROM TabGproducts ORDER BY GpName", sqlConnection);
			DataSet dataSet = new DataSet();
			sqlDataAdapter.Fill(dataSet);
			this.dgvGroup.DataSource = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		private void getListProduct(string gid)
		{
			SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
			sqlConnection.Open();
			SqlDataAdapter sqlDataAdapter = new SqlDataAdapter("SELECT PID, P_Name, interaction FROM TabProducts WHERE GpID = " + gid + " ORDER BY P_Name", sqlConnection);
			DataSet dataSet = new DataSet();
			sqlDataAdapter.Fill(dataSet);
			this.dgvProduct.DataSource = dataSet.Tables[0];
			sqlConnection.Close();
			sqlConnection.Dispose();
		}
		private void frmInteractionProduct_Load(object sender, EventArgs e)
		{
			this.getListGroupProduct();
		}
		private void dgvGroup_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.getListProduct(this.dgvGroup.Rows[e.RowIndex].Cells["GpID"].Value.ToString());
			}
			catch
			{
			}
		}
		private void dgvProduct_CellEnter(object sender, DataGridViewCellEventArgs e)
		{
			try
			{
				this.currIndex = e.RowIndex;
				this.currPid = int.Parse(this.dgvProduct.Rows[e.RowIndex].Cells["Pid"].Value.ToString());
				this.txtIntraction.Text = this.dgvProduct.Rows[e.RowIndex].Cells["interaction"].Value.ToString();
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				this.currPid = 0;
			}
		}
		private void btnEdit_Click(object sender, EventArgs e)
		{
			this.btnSave.Enabled = true;
			this.txtIntraction.ReadOnly = false;
			this.btnEdit.Enabled = false;
		}
		private void btnSave_Click(object sender, EventArgs e)
		{
			if (this.txtIntraction.Text.Trim() != "")
			{
				this.updateInteraction(this.currPid, this.txtIntraction.Text);
				this.btnEdit.Enabled = true;
				this.btnSave.Enabled = false;
				this.txtIntraction.ReadOnly = true;
			}
			else
			{
				MessageBox.Show("Nhập vào thông tin về tính tương tác của thuốc", "Cảnh báo", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
			}
		}
		private void updateInteraction(int pid, string interaction)
		{
			try
			{
				SqlConnection sqlConnection = new SqlConnection(Program.strConnectionString);
				sqlConnection.Open();
				SqlCommand sqlCommand = new SqlCommand("UPDATE TabProducts SET interaction = @interaction WHERE pid = @pid", sqlConnection);
				SqlParameter sqlParameter = new SqlParameter("interaction", SqlDbType.NVarChar);
				SqlParameter sqlParameter2 = new SqlParameter("pid", SqlDbType.Int);
				sqlParameter.Value = interaction;
				sqlParameter2.Value = pid;
				sqlCommand.Parameters.Add(sqlParameter);
				sqlCommand.Parameters.Add(sqlParameter2);
				sqlCommand.ExecuteNonQuery();
				sqlConnection.Close();
				sqlConnection.Dispose();
				this.dgvProduct.Rows[this.currIndex].Cells["interaction"].Value = interaction;
			}
			catch
			{
			}
		}
		private void btnClose_Click(object sender, EventArgs e)
		{
			base.Close();
		}
		private void frmInteractionProduct_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.KeyCode == Keys.Escape)
			{
				this.btnClose.PerformClick();
			}
		}
	}
}
